package com.springboot.erp.controller;

import com.springboot.erp.common.CommonResult;
import com.springboot.erp.entity.JshAccountHead;
import com.springboot.erp.entity.ReceiptDTO;
import com.springboot.erp.service.ReceiptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/receipt")
@Slf4j
public class ReceiptController {

    @Resource
    ReceiptService receiptService;
    @RequestMapping("/{id}")
    public CommonResult<ReceiptDTO> selectReceiptById(@PathVariable Long id) {
        return CommonResult.success(receiptService.selectReceiptById(id));
    }

    @GetMapping("/listReceipts")
    public CommonResult<List<JshAccountHead>> listReceipts(Long organId, String status, Date startDate, Date endDate) {
        List<JshAccountHead> receipts = receiptService.listReceipts(organId, status, startDate, endDate);
        return CommonResult.success(receipts);
    }

    @PostMapping
    public CommonResult<Void> addOne(@RequestBody JshAccountHead jshAccountHead) {
        receiptService.addOne(jshAccountHead);
        return new CommonResult( 0, "success", null);
    }
    @PutMapping
    public CommonResult<Void> updateOne(@RequestBody JshAccountHead jshAccountHead) {
        receiptService.updateOne(jshAccountHead);
        return new CommonResult( 0, "success", null);
    }
    @DeleteMapping("/{id}")
    public CommonResult<Void> deleteOne(@PathVariable Integer id) {
        receiptService.deleteOne(id);
        return new CommonResult( 0, "success", null);
    }
}
